<template>
    <div class="goods">
        <div class="commodityLists">
            <p class="commodityTitle">———————— 为您推荐 ————————</p>
            <dl v-for="(item,index) in GoodsList" @click="jumpToCommodity(item.gid)">
                <dt>
                    <img v-lazy="item.image" alt=""/>
                </dt>
                <dd>
                    <p>{{item.title}}</p>
                    <p class="price">¥{{item.price}}</p>
                </dd>
            </dl>
        </div>
    </div>
</template>
<script>
    import {getGoodsList} from "../../api/list/list";

    export default {
        name:'Goods',
        data(){
            return {
                GoodsList:[]
            }
        },
        created() {
            getGoodsList().then((res)=>{
                let data = res.data.data
                this.GoodsList = data
            })
        },
        methods:{
            jumpToCommodity(id){
                this.$router.push({path:'/commodity/index',query:{gid:id}})
            }
        }
    }
</script>
<style lang="less" scoped>
    .goods {
        width: 100%;
        p{
            margin: 0;
        }
        dl:nth-child(odd){
            margin-left: 0.2rem;
        }
        dl {
            width: 48%;
            float: left;
            background: white;
            padding: 0.1rem;
            box-sizing: border-box;
            margin-top: 0.2rem;
            dt{
                width: 100%;
                display: flex;
                align-items: center;
                justify-content: center;
                img{
                    width: 100%;
                    height: auto;
                    display: block;
                }
            }
            dd{
                width: 97%;
                text-align: left;
                p{
                    height: 0.8rem;
                    display: -webkit-box;
                    text-align: center;
                    overflow:hidden;
                    text-overflow:ellipsis;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                    margin: 0 auto;
                    line-height: 0.4rem;
                    text-align: left;
                }
                .price{
                    text-align: left;
                    color: red;
                    height: 0.3rem;
                }
            }
        }
        .commodityTitle{
            height: 1rem;
            text-align: center;
            line-height: 1rem;
        }
    }
</style>